/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingServUserManageInfo: {
                housekeepingServUsers: [],
                total: 0,
                records: 1,
                moreCondition: false,
                servUserId: '',
                servName: '',
                servId: '',
                conditions: {
                    state: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that.housekeepingServUserManageInfo.conditions.servId = vc.getParam('servId');
            $that.housekeepingServUserManageInfo.servName = vc.getParam('servName');
            $that.housekeepingServUserManageInfo.servId = vc.getParam('servId');
            $that._listHousekeepingServUsers(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('housekeepingServUserManage', 'listHousekeepingServUser', function (_param) {
                $that._listHousekeepingServUsers(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (DEFAULT_PAGE) {
                $that._listHousekeepingServUsers(DEFAULT_PAGE, DEFAULT_ROWS);
            });
        },
        methods: {
            _listHousekeepingServUsers: function (_page, _rows) {
                $that.housekeepingServUserManageInfo.conditions.page = _page;
                $that.housekeepingServUserManageInfo.conditions.row = _rows;
                let param = {
                    params: $that.housekeepingServUserManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/housekeepingServUser/queryHousekeepingServUser',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingServUserManageInfo.total = _json.total;
                        $that.housekeepingServUserManageInfo.records = _json.records;
                        $that.housekeepingServUserManageInfo.housekeepingServUsers = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.housekeepingServUserManageInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddHousekeepingServUserModal: function () {
                vc.emit('addHousekeepingServUser', 'openAddHousekeepingServUserModal', {});
            },
            _openEditHousekeepingServUserModel: function (_housekeepingServUser) {
                vc.emit('editHousekeepingServUser', 'openEditHousekeepingServUserModal', _housekeepingServUser);
            },
            _openDeleteHousekeepingServUserModel: function (_housekeepingServUser) {
                vc.emit('deleteHousekeepingServUser', 'openDeleteHousekeepingServUserModal', _housekeepingServUser);
            },
            _queryHousekeepingServUserMethod: function () {
                $that._listHousekeepingServUsers(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _goBack: function () {
                vc.goBack()
            },
            _openAddRepairTypeUserModal: function () {
                vc.emit('selectStaff', 'openStaff', {
                    call: function (_staff) {
                        $that.saveHousekeepingServUserInfo(_staff);
                    }
                });
            },
            saveHousekeepingServUserInfo: function (_staff) {
                let param = {
                    shopId: vc.getCurrentCommunity().shopId,
                    staffId: _staff.staffId,
                    staffName: _staff.staffName,
                    servId: $that.housekeepingServUserManageInfo.servId,
                    state: '9999'
                }
                vc.http.apiPost(
                    '/housekeepingServUser/saveHousekeepingServUser',
                    JSON.stringify(param),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#selectStaffModel').modal('hide');
                            $that._listHousekeepingServUsers(DEFAULT_PAGE, DEFAULT_ROWS);
                            vc.toast("添加成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _moreCondition: function () {
                if ($that.housekeepingServUserManageInfo.moreCondition) {
                    $that.housekeepingServUserManageInfo.moreCondition = false;
                } else {
                    $that.housekeepingServUserManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
